using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using YooAsset;

public class TestLoad : MonoBehaviour
{
    public GameEntry _gameEntry;

    public RawImage img1, img2;

    void Start()
    {
        PackageData data0 = new PackageData(_packageName: "DefaultPackage", _appVersion: "v1.0");
        PackageData data1 = new PackageData(_packageName: "DefaultPackage1", _appVersion: "v1.0");
        
        data0.OnLoadFinishAction += () =>
        {
            Debug.Log("资源初始化完毕！");
            StartCoroutine(LoadTex("DefaultPackage", "plus", tex => { img1.texture = tex; }));
        };

        data1.OnLoadFinishAction += () =>
        {
            Debug.Log("资源初始化完毕！");
            StartCoroutine(LoadTex("DefaultPackage1", "arrow1_left", tex => { img2.texture = tex; }));
        };
        _gameEntry.LoadPackage(data0);
        _gameEntry.LoadPackage(data1);
    }

    IEnumerator LoadTex(string packageName, string texName,Action<Texture> callback)
    {
      var handle =  YooAssets.GetPackage(packageName).LoadAssetAsync<Texture>(texName);
      yield return handle;
      callback.Invoke(handle.AssetObject as Texture);
      yield return 0;
    }
}
